package LevelEditor;

import GameEngine.GameConstants;
import GameEngine.GameConstants.Modifier;
import GameEngine.Vector;
import java.awt.BorderLayout;

import javax.swing.JComponent;
import javax.swing.JPanel;

/**
 * Class of static GUI methods
 * @author WhateverWillIDo
 *
 */

public class EditorFunctions {
	
	/**
	 * Returns a JPanel that is "padded" on all four sides
	 * @param miniP
	 * @return
	 */

    private static final float one_sqrtTwo = (float) ((float) 1 / Math.sqrt(2));
	
	public static JPanel getSpace(JComponent miniP) {
		JPanel returnP = new JPanel();
		returnP.setLayout(new BorderLayout());
		
		String[] dir = {BorderLayout.NORTH, BorderLayout.EAST, BorderLayout.WEST, BorderLayout.SOUTH};
		for (String d : dir) {
			returnP.add(new JPanel(), d);
		}
		
		returnP.add(miniP, BorderLayout.CENTER);
		
		return returnP;
	}

    /**
     * Checks to see if the given type has a special add behavior
     * @param type
     * @return
     */

    public static boolean isSpecialAdd(GameConstants.Thing type) {
        switch (type) {
            case WALL:
               return true;
            default:
               return false;
        }
    }

    /**
     * Returns a vector from a Modifier enum
     * @param m
     * @return
     */

    public static Vector getVector(Modifier m) {
        Vector toReturn = null;
        switch (m) {
            case UP:
                toReturn = new Vector(0, -1);
                break;
            case DOWN:
                toReturn = new Vector(0, 1);
                break;
            case LEFT:
                toReturn = new Vector(-1, 0);
                break;
            case RIGHT:
                toReturn = new Vector(1, 0);
                break;
            case UPLEFT:
                toReturn = new Vector(-one_sqrtTwo, -one_sqrtTwo);
                break;
            case UPRIGHT:
                toReturn = new Vector(one_sqrtTwo, -one_sqrtTwo);
                break;
            case DOWNLEFT:
                toReturn = new Vector(-one_sqrtTwo, one_sqrtTwo);
                break;
            case DOWNRIGHT:
                toReturn = new Vector(one_sqrtTwo, one_sqrtTwo);
                break;
            default:
                toReturn = new Vector(1, 0);
                break;
        }
        return toReturn;
    }

    public static Vector normalize(Vector v) {
        double scaleConstant = Math.sqrt(v.getX()*v.getX() + v.getY()*v.getY());
        return v.scaleNew(1/scaleConstant);
    }

}
